/***
 *   @title qz
 *   @description <description class purpose>
 *   @author yichen
 *   @version 1.0.0
 *   @create 2023/9/23 0023
 **/
package io.gitee.wokaixin.yunque.driver;

public class DriverFactory {
    private RedisConfig redisConfig;
    private KafkaConfig kafkaConfig;
    private KafkaDriver kafkaDriver;
    private RedisDriver redisDriver;

    public DriverFactory() {
    }


    public DriverFactory(KafkaConfig kafkaConfig) {
        setDriverFactory(kafkaConfig);
    }

    public DriverFactory(RedisConfig redisConfig) {
        setDriverFactory(redisConfig);
    }

    public void setDriverFactory(RedisConfig redisConfig) {
        this.redisConfig = redisConfig;
        this.redisDriver = new RedisDriver(redisConfig);
        this.redisDriver.setChannelName(redisConfig.getChannelName());
    }

    public void setDriverFactory(KafkaConfig kafkaConfig) {
        this.kafkaConfig = kafkaConfig;
        this.kafkaDriver = new KafkaDriver(kafkaConfig);
        this.kafkaDriver.setTopic(kafkaConfig.getTopic());
    }

    public Driver getDriver(String type) {
        if (type.equals("redis")) {
            return this.redisDriver;
        } else {
            return this.kafkaDriver;
        }
    }

}
